<?php
/**
 * 首页
 * User: Acer
 * Date: 2022/7/22
 * Time: 21:12
 */
namespace app\admin\controller;

use app\admin\service\HomeService;
use app\core\MyController as MyController;

class Home extends MyController
{
    protected  $noNeedAction = ['*']; // 不需要校验控制器，通道
    // 操作前置
    protected $beforeActionList = ['my_initialize'];

    // 操作前置方法
    public function my_initialize(){
//        $this->is_admin();  // 权限检查
    }

    // 首页用户统计
    public function statistics_user(){
        $data = input();
        if(empty($data['start_time']) || empty($data['end_time']) ) json_err( -201);
        $HomeService =  new HomeService();
        $res_data['list'] =  $HomeService->s_statistics_user($data);
        $res_data['total_number'] = 0; // 总人数
        $res_data['attestation_number'] = 0; // 认证人数
        if($res_data['list']){
                $key = count($res_data['list']) - 1;
                $res_data['total_number'] = $res_data['list'][$key]['total_number'] ;
                $res_data['attestation_number'] = $res_data['list'][$key]['attestation_number'];
        }
        _action_result(200,$res_data,'操作成功！');

    }
    // 首页卡片统计
    public function statistics_card(){
        $data = input();
        if( empty($data['start_time']) || empty($data['end_time']) ) json_err( -201);
        $HomeService =  new HomeService();
        $res_data['list'] =  $HomeService->s_statistics_card($data);
        $res_data['active_number'] = 0; // 激活卡片总数
        $res_data['active_family_number'] = 0; // 家庭卡激活数
        $res_data['active_personal_number'] = 0; // 个人卡激活数
        $res_data['active_qmx_number'] = 0; // 全明星激活数
        $res_data['active_my_number'] = 0; // 名医激活数
        $res_data['total_number'] = 0; // 总计卡片数
        if($res_data['list']){
                $key = count($res_data['list']) - 1;
                $res_data['active_number'] = $res_data['list'][$key]['active_number'];
                $res_data['active_family_number'] =  $res_data['list'][$key]['active_family_number'];
                $res_data['active_personal_number'] = $res_data['list'][$key]['active_personal_number'];
                $res_data['active_qmx_number'] = $res_data['list'][$key]['active_qmx_number'];
                $res_data['active_my_number'] = $res_data['list'][$key]['active_my_number'];
                $res_data['total_number'] =  $res_data['list'][$key]['total_number'];
        }
         _action_result(200,$res_data,'操作成功！');

    }


}
